package com.bby.disk.config;

import com.bby.common.config.GlobalSettings;
import com.bby.disk.manager.upload.OfflineThreadManager;
import com.bby.disk.manager.virtual.VirtualManager;
import org.bytedeco.ffmpeg.global.avutil;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;

import javax.annotation.Resource;
import java.io.File;

@Configuration
public class GlobalConfig implements InitializingBean {
    @Value(value = "${settings.rootPath}")
    String rootPath;
    @Value(value = "${settings.TEMP_FILE_MILLISECOND}")
    Long UPLOAD_TASK_MAX_AGE;


    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public void afterPropertiesSet() throws Exception {
        GlobalSettings.TEMP_FILE_MILLISECOND=UPLOAD_TASK_MAX_AGE;
        GlobalSettings.ROOT_PATH=rootPath;
//        GlobalSettings.USERS_DIR=rootPath+ File.separator+"users";
//        GlobalSettings.DISK_ROOTS_DIR=rootPath+ File.separator+"roots";
        GlobalSettings.TEMP_FILES_DIR=rootPath+ File.separator+"temps";
        // 设置 javacv
        avutil.av_log_set_level(avutil.AV_LOG_WARNING);

        // 设置静态 Manager
        OfflineThreadManager.mongoTemplate = mongoTemplate;
        VirtualManager.mongoTemplate = mongoTemplate;
    }
}
